package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.VirtualGpu;
import com.accelstack.cmp.enums.VirtualGpuStatus;
import com.accelstack.cmp.repository.VirtualGpuRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 虚拟GPU Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class VirtualGpuService {
    
    private final VirtualGpuRepository virtualGpuRepository;
    
    @Transactional
    public VirtualGpu create(VirtualGpu virtualGpu) {
        return virtualGpuRepository.save(virtualGpu);
    }
    
    @Transactional
    public VirtualGpu update(VirtualGpu virtualGpu) {
        return virtualGpuRepository.save(virtualGpu);
    }
    
    @Transactional
    public void deleteById(Long id) {
        virtualGpuRepository.deleteById(id);
    }
    
    public Optional<VirtualGpu> findById(Long id) {
        return virtualGpuRepository.findById(id);
    }
    
    public List<VirtualGpu> findAll() {
        return virtualGpuRepository.findAll();
    }
    
    public Page<VirtualGpu> findAll(Pageable pageable) {
        return virtualGpuRepository.findAll(pageable);
    }
    
    public List<VirtualGpu> findByVirtHostId(Long virtHostId) {
        return virtualGpuRepository.findByVirtHostId(virtHostId);
    }
    
    public List<VirtualGpu> findByStatus(VirtualGpuStatus status) {
        return virtualGpuRepository.findByStatus(status);
    }
}

